﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using GPCSC.Model;
using GPCSC.DALFactory;
using GPCSC.IDAL;
namespace GPCSC.BLL
{
	/// <summary>
	/// newstable
	/// </summary>
	public partial class newstable
	{
		private readonly Inewstable dal=DataAccess.Createnewstable();
		public newstable()
		{}
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(Guid NewsID)
		{
			return dal.Exists(NewsID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(GPCSC.Model.newstable model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(GPCSC.Model.newstable model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(Guid NewsID)
		{
			
			return dal.Delete(NewsID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string NewsIDlist )
		{
			return dal.DeleteList(NewsIDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public GPCSC.Model.newstable GetModel(Guid NewsID)
		{
			
			return dal.GetModel(NewsID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public GPCSC.Model.newstable GetModelByCache(Guid NewsID)
		{
			
			string CacheKey = "newstableModel-" + NewsID;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(NewsID);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (GPCSC.Model.newstable)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<GPCSC.Model.newstable> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<GPCSC.Model.newstable> DataTableToList(DataTable dt)
		{
			List<GPCSC.Model.newstable> modelList = new List<GPCSC.Model.newstable>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				GPCSC.Model.newstable model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new GPCSC.Model.newstable();
					if(dt.Rows[n]["NewsID"]!=null && dt.Rows[n]["NewsID"].ToString()!="")
					{
						model.NewsID=new Guid(dt.Rows[n]["NewsID"].ToString());
					}
					if(dt.Rows[n]["NewsTitles"]!=null && dt.Rows[n]["NewsTitles"].ToString()!="")
					{
					model.NewsTitles=dt.Rows[n]["NewsTitles"].ToString();
					}
					if(dt.Rows[n]["Newscontent"]!=null && dt.Rows[n]["Newscontent"].ToString()!="")
					{
					model.Newscontent=dt.Rows[n]["Newscontent"].ToString();
					}
					if(dt.Rows[n]["FBdate"]!=null && dt.Rows[n]["FBdate"].ToString()!="")
					{
						model.FBdate=dt.Rows[n]["FBdate"].ToString();
					}
					if(dt.Rows[n]["BTSBLMID"]!=null && dt.Rows[n]["BTSBLMID"].ToString()!="")
					{
						model.BTSBLMID=new Guid(dt.Rows[n]["BTSBLMID"].ToString());
					}
					if(dt.Rows[n]["BTSBLMName"]!=null && dt.Rows[n]["BTSBLMName"].ToString()!="")
					{
					model.BTSBLMName=dt.Rows[n]["BTSBLMName"].ToString();
					}
					if(dt.Rows[n]["IsImageNews"]!=null && dt.Rows[n]["IsImageNews"].ToString()!="")
					{
						model.IsImageNews=int.Parse(dt.Rows[n]["IsImageNews"].ToString());
					}
					if(dt.Rows[n]["IsDel"]!=null && dt.Rows[n]["IsDel"].ToString()!="")
					{
						model.IsDel=int.Parse(dt.Rows[n]["IsDel"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

